package com.lxd.sunso.product.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.lxd.sunso.common.utils.PageUtils;
import com.lxd.sunso.common.utils.R;
import com.lxd.sunso.product.vo.CustomerVo;
import com.lxd.sunso.product.vo.MachineKindVo;
import com.lxd.sunso.product.vo.MachineNameAndIdVo;
import com.lxd.sunso.product.vo.MachineVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.lxd.sunso.product.entity.MachinekindEntity;
import com.lxd.sunso.product.service.MachinekindService;
import org.springframework.web.multipart.MultipartFile;


/**
 * @author lxd
 * @email sunlightcs@gmail.com
 * @date 2020-12-30 18:06:30
 */
@RestController
@RequestMapping("product/machinekind")
public class MachinekindController {
    @Autowired
    private MachinekindService machinekindService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("product:machinekind:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = machinekindService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("product:machinekind:info")
    public R info(@PathVariable("id") Long id) {
        MachinekindEntity machinekind = machinekindService.getById(id);
        return R.ok().put("machinekind", machinekind);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("product:machinekind:save")
    public R save(MultipartFile file, MachinekindEntity machinekind) {
        machinekindService.saveKind(machinekind, file);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("product:machinekind:update")
    public R update(MultipartFile file, MachinekindEntity machinekind) {
        machinekindService.updateKind(machinekind, file);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("product:machinekind:delete")
    public R delete(@RequestBody Long[] ids) {
        machinekindService.delete(Arrays.asList(ids));
        return R.ok();
    }

    /**
     * 根据设备型号的Id进行搜索
     */
    @RequestMapping("/search/{id}")
    public R search(@PathVariable Long id) {
        List<MachinekindEntity> list = machinekindService.search(id);
        return R.ok().put("list", list);
    }

    /**
     * 获取所有的设备型号和Id
     */
    @RequestMapping("/getMachineKindAndId")
    public R getMachineKindAndId() {
        List<MachineKindVo> list = machinekindService.getMachineKindAndId();
        return R.ok().put("list", list);
    }

    /**
     * 根据设备型号名称获取所有的设备
     */
    @RequestMapping("/getMahicneByKindName/{machineKind}")
    public R getMachineByKind(@PathVariable String machineKind) {
        List<MachineNameAndIdVo> list = machinekindService.getMahicneByKindName(machineKind);
        return R.ok().put("list", list);
    }

    /**
     * 根据设备型号获取所属客户
     */
    @RequestMapping("/getCustomerByKindName/{machineKind}")
    public R getCustomerByKindName(@PathVariable String machineKind) {
        List<CustomerVo> list = machinekindService.getCustomerByKindName(machineKind);
        return R.ok().put("list", list);
    }
}
